<?php
    //加载初始化文件
    include_once('init.php');

    //新闻添加
    if(!empty($_POST)){

    //获取地址栏中参数名是id的值
 	$id = $_POST['id'];

    //获取$_POST数据
    $title = $_POST['title'];

    $type = $_POST['type'];

    $content = $_POST['content'];


    //编写添加的sql语句
    $sql = "update `news` set `title`='$title',`type`='$type',`content`='$content' where `id` = $id";

    //执行语句
    mysqli_query($link,$sql);

    //获取刚刚执行的添加语句受影响的行数(就是你插入的数据的记录总数)
    $_rows = mysqli_affected_rows($link);

    if($_rows>0){
       echo '<script>alert("新闻编辑成功");location.href="news_list.php";</script>';die;
    }else{
    	echo '<script>alert("新闻编辑失败");history.go(-1);</script>';die;
    }

}

//获取地址栏中参数名是id的值
$id = $_GET['id'];

//编写查询语句
$sql = "select * from `news` where `id` = $id";

//执行语句
$result = mysqli_query($link,$sql);

//从结果集中获取查询到的数据
$data = mysqli_fetch_assoc($result);

include('news_edit.html');